/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.stylefeng.guns.core.common.exception;

import cn.stylefeng.roses.kernel.model.exception.AbstractBaseExceptionEnum;

/**
 * @author fengshuonan
 * @Description 所有业务异常的枚举
 * @date 2016年11月12日 下午5:04:51
 */
public enum BizExceptionEnum implements AbstractBaseExceptionEnum {
    SUCCESS(200,"请求成功"),

    /**
     * 字典
     */
    DICT_EXISTED(400, "字典已经存在"),
    ERROR_CREATE_DICT(500, "创建字典失败"),
    ERROR_WRAPPER_FIELD(500, "包装字典属性失败"),
    ERROR_CODE_EMPTY(500, "字典类型不能为空"),

    /**
     * 文件上传
     */
    FILE_READING_ERROR(400, "FILE_READING_ERROR!"),
    FILE_NOT_FOUND(400, "FILE_NOT_FOUND!"),
    UPLOAD_ERROR(500, "上传图片出错"),

    /**
     * 权限和数据问题
     */
    DB_RESOURCE_NULL(400, "数据库中没有该资源"),
    NO_PERMITION(405, "权限异常"),
    REQUEST_INVALIDATE(400, "请求数据格式不正确"),
    INVALID_KAPTCHA(400, "验证码不正确"),
    CANT_DELETE_ADMIN(600, "不能删除超级管理员"),
    CANT_FREEZE_ADMIN(600, "不能冻结超级管理员"),
    CANT_CHANGE_ADMIN(600, "不能修改超级管理员角色"),

    /**
     * 账户问题
     */
    NOT_LOGIN(401, "当前用户未登录"),
    USER_ALREADY_REG(401, "该用户已经注册"),
    USER_ALREADY_PHONE(403, "该手机号已经注册"),
    NO_THIS_USER(400, "没有此用户"),
    USER_NOT_EXISTED(400, "没有此用户"),
    ACCOUNT_FREEZED(401, "账号被冻结"),
    OLD_PWD_NOT_RIGHT(402, "原密码不正确"),
    TWO_PWD_NOT_MATCH(405, "两次输入密码不一致"),
    LIMIT_OPERATE_SELF(406, "不允许操作自己账号"),
    USER_INFO_NOT_RIGHT(402, "系统已经存在该用户，本次提交信息与用户身份证号、姓名和手机号不一致，请修改身份信息"),
    USER_ALREADY_IDCARD(403, "该身份证已经注册"),
    AGE_NOT_ALLOW(408,"年龄超出限制"),

    /**
     * 栏目
     */
    EXIT_SUB_COLUMN(501,"请先删除下级栏目"),
    EXIT_NEWS(503,"请先删除栏目下新闻"),

    /**
     * 错误的请求
     */
    MENU_PCODE_COINCIDENCE(400, "菜单编号和副编号不能一致"),
    EXISTED_THE_MENU(400, "菜单编号重复，不能添加"),
    DICT_MUST_BE_NUMBER(400, "字典的值必须为数字"),
    REQUEST_NULL(400, "请求有错误"),
    SESSION_TIMEOUT(400, "会话超时"),
    SERVER_ERROR(500, "服务器异常"),

    /**
     * token异常
     */
    TOKEN_EXPIRED(700, "token过期"),
    TOKEN_ERROR(700, "token验证失败"),

    /**
     * 签名异常
     */
    SIGN_ERROR(700, "签名验证失败"),

    /**
     * 其他
     */
    AUTH_REQUEST_ERROR(400, "账号或密码错误"),

    /**
     * 课程
     */
    MAJOR_EXIT(300,"课程已存在"),
    /**
     * 时段
     */
    TIME_EXIT(300,"时段已存在"),

    /**
     * 阶段
     * @param code
     * @param message
     */
    LEVEL_NOT_EXIT(300,"该年度下没有可以导出的任务"),
    LEVEL_NOT_EXIT_COPY(300,"当前选择年度没有可以复制的任务"),
    TARGET_LEVEL_EXIT(300,"目标年度已存在任务，请先删除"),

    FILES_NOT_EXIT(400,"没有已经完成的任务，无法导出"),

    SCORE_OUT(400,"设置分值不能大于最大评判分"),

    DEPT_NOFILE(301,"该部门没有可以导出的资料"),
    PARENT_NOT_SELECT(302,"请选择左侧目录"),
    USER_NODEPT(302,"登录用户未设置部门");



    BizExceptionEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private Integer code;

    private String message;

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String getMessage(int code){
        for(BizExceptionEnum e : BizExceptionEnum.values()){
            if(e.getCode() == code){
                return e.getMessage();
            }
        }
        return null;
    }
}
